package com.jiazhong.commons.exception;

import com.jiazhong.commons.Util.JsonResult;
import com.jiazhong.commons.Util.ResultTool;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;

@RestControllerAdvice
public class GlobalException {
    @ExceptionHandler(UserRemoveException.class)
    public JsonResult userRemove(Throwable e) {
        return ResultTool.fail(5001, e.getMessage());
    }

    @ExceptionHandler(UserSaveException.class)
    public JsonResult userSave(Throwable e) {
        return ResultTool.fail(5002, e.getMessage());
    }

    @ExceptionHandler(UserNotFoundDataException.class)
    public JsonResult userNotFoundData(Throwable e) {
        return ResultTool.fail(5003, e.getMessage());
    }

    @ExceptionHandler(UserExistsException.class)
    public JsonResult userExists(Throwable e) {
        return ResultTool.fail(5004, e.getMessage());
    }

    @ExceptionHandler(SQLException.class)
    public JsonResult sql(Throwable e) {
        return ResultTool.fail(5000, e.getMessage());
    }

    @ExceptionHandler(BookSaveException.class)
    public JsonResult bookSave(Throwable e) {
        return ResultTool.fail(5005, e.getMessage());
    }

    @ExceptionHandler(BookNotFoundException.class)
    public JsonResult bookNotFound(Throwable e) {
        return ResultTool.fail(5006, e.getMessage());
    }

    @ExceptionHandler(BookRemoveException.class)
    public JsonResult bookRemove(Throwable e) {
        return ResultTool.fail(5007, e.getMessage());
    }

    @ExceptionHandler(BookExistsException.class)
    public JsonResult bookExists(Throwable e) {
        return ResultTool.fail(5008, e.getMessage());
    }

    @ExceptionHandler(CategoryNotFoundException.class)
    public JsonResult CategoryNotFound(Throwable e) {
        return ResultTool.fail(5009, e.getMessage());
    }

    @ExceptionHandler(CategorySaveException.class)
    public JsonResult CategorySave(Throwable e) {
        return ResultTool.fail(5010, e.getMessage());
    }

    @ExceptionHandler(CategoryExistsException.class)
    public JsonResult CategoryExists(Throwable e) {
        return ResultTool.fail(5011, e.getMessage());
    }

    @ExceptionHandler(CategoryRemoveExistsException.class)
    public JsonResult CategoryRemove(Throwable e) {
        return ResultTool.fail(5012, e.getMessage());
    }

    @ExceptionHandler(UserUpdatePasswordException.class)
    public JsonResult userUpdatePassword(Throwable e) {
        return ResultTool.fail(5013, e.getMessage());
    }

    @ExceptionHandler(InputPasswordFailException.class)
    public JsonResult inputPasswordFail(Throwable e) {
        return ResultTool.fail(5014, e.getMessage());
    }

    @ExceptionHandler(UserUpdateException.class)
    public JsonResult userUpdate(Throwable e) {
        return ResultTool.fail(5015, e.getMessage());
    }

    @ExceptionHandler(UsernameNotFoundException.class)
    public JsonResult usernameNotFound(Throwable e) {
        return ResultTool.fail(6001, e.getMessage());
    }

    @ExceptionHandler(PasswordErrorException.class)
    public JsonResult passwordError(Throwable e) {
        return ResultTool.fail(6002, e.getMessage());
    }

    @ExceptionHandler(LoginFailException.class)
    public JsonResult loginFail(Throwable e) {
        return ResultTool.fail(6000, e.getMessage());
    }

    @ExceptionHandler(NotLoginException.class)
    public JsonResult notLogin(Throwable e) {
        return ResultTool.fail(6002, e.getMessage());
    }

    @ExceptionHandler(GwcIsEmptyException.class)
    public JsonResult gwcIsEmpty(Throwable e) {
        return ResultTool.fail(6003, e.getMessage());
    }

    @ExceptionHandler(StockFailException.class)
    public JsonResult stockFail(Throwable e) {
        return ResultTool.fail(6004, e.getMessage());
    }
}
